    function initialize() {
      var map = new L.Map('map').setView(new L.LatLng(39.8, -98.2), 4)
        , mapboxUrl = 'http://{s}.tiles.mapbox.com/v3/cartodb.map-1nh578vv/{z}/{x}/{y}.png'
        , mapbox = new L.TileLayer(mapboxUrl, {maxZoom: 18, attribution: ""});
      map.addLayer(mapbox,true);

      // Now the CartoDB layer, the counties
      county = new L.CartoDBLayer({
        map: map,
        user_name:"statmath",
        table_name: 'uscounties',
        query: "SELECT cartodb_id,the_geom,the_geom_webmercator,name,state_name FROM {{table_name}}",
        tile_style: "#{{table_name}}{polygon-fill: rgba(128,128,128,1) }",
        auto_bound: false,
        debug: false
      });
      //map.addLayer(county);

      // Create a CartoDB popup
      var popup = new L.CartoDBPopup();
      var hover_style = {radius:5, color:"#333", weight:1, opacity:1, fillColor: "#FFCC00", fillOpacity:1, clickable:true};
      var circleMarker = {};
      var query = "SELECT the_geom,the_geom_webmercator,state,county,count(county) AS npics, ST_X(the_geom) AS lng,ST_Y(the_geom) AS lat FROM {{table_name}} GROUP BY the_geom,the_geom_webmercator,state,county";

      // Now the CartoDB layer, the photographs
      earthquakes = new L.CartoDBLayer({
        map: map,
        user_name:"statmath",
        table_name: 'fsadata',
        query: query,
        tile_style: "#{{table_name}}{marker-opacity:0.5; marker-fill:#006BB4; marker-allow-overlap:true; marker-width:6; marker-height:6}",
        interactivity: "state,county,npics,lng,lat",
        featureOver: function(ev,latlng,pos,data) {
          document.body.style.cursor = "pointer";

            if (data.county != circleMarker.county) {
              map.removeLayer(circleMarker);
            
              circleMarker = new L.CircleMarker(new L.LatLng(data.lat, data.lng), hover_style);
              circleMarker.county = data.county;
              
              map.addLayer(circleMarker);
            }

        },
        featureOut: function() {
          document.body.style.cursor = "default";

            // Hide and remove in any case the hover point
            circleMarker.county = null;
            map.removeLayer(circleMarker)

        },
        featureClick: function(ev,latlng,pos,data) {
          ev.stopPropagation();
          // Set popup content
          var stateName = data["state"];
          var stateNameUrl = stateName.replace(" ","+"); 
          var countyName = data["county"];
          var countyNameUrl = countyName.replace(" ","+"); 
          popup.setContent(stateName + " - <br/> " + countyName + '<br/><br/> <a href="http://photogrammar.yale.edu/asearch/results.php?start=0&pname=&lot=&van=&state=' + stateNameUrl + '&county=' + countyNameUrl +'&city=&year_start=1935&year_stop=1945&month_start=1&month_stop=12">' + 'SEE ' + data["npics"] + ' PHOTOS</a>');

          popup.setContent(stateName + '<div id="map-popup-county">' + countyName + '</div><div id="map-popup-link"><a href="http://photogrammar.yale.edu/search/results.php?start=0&search=&pname=&lot=&van=&state=' + stateNameUrl + '&county=' + countyNameUrl +'&city=&year_start=1935&month_start=1&year_stop=1945&month_stop=12">' + 'See ' + data["npics"] + ' Photos</a></div>');

          // Set latlng
          popup.setLatLng(latlng);

          // Show it!
          map.openPopup(popup);
        },
        auto_bound: false,
        debug: false
      });
      // Adding layer to map
      map.addLayer(earthquakes);
    }

    function changeLayer(year_start, month_start, year_end, month_end, pname) {
          var dstart = year_start + (month_start-1)/12;
          var dend = year_end + (month_end-1)/12;
          if(pname == "All") {
              qry = "SELECT the_geom,the_geom_webmercator,state,county,count(county) AS npics, ST_X(the_geom) AS lng,ST_Y(the_geom) AS lat FROM {{table_name}} WHERE year + (month-1)/12 >=" + dstart + " AND year + (month-1)/12 <= " + dend + " GROUP BY the_geom,the_geom_webmercator,state,county";
            } else {
              qry = "SELECT the_geom,the_geom_webmercator,state,county,count(county) AS npics, ST_X(the_geom) AS lng,ST_Y(the_geom) AS lat FROM {{table_name}} WHERE year + (month-1)/12 >=" + dstart + " AND year + (month-1)/12 <= " + dend + " AND pname ='" + pname + "' GROUP BY the_geom,the_geom_webmercator,state,county";
            }
          earthquakes.setQuery(qry);
      }

    function onChange() {      
      if ($('input[type="checkbox"]').attr("checked")) {
        county.show()
      } else {
        county.hide()
      }
    }





